﻿package mortal.game.view.rebate.openNewSerSevenDay.items
{
    import Message.Game.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class OpenServerSevDayRC200 extends BaseWindow
    {
        protected var _bg:GImageBitmap;
        protected var _namtTxt:GTextFiled;
        protected var _des:GTextFiled;
        protected var _comsumNum:GTextFiled;
        protected var _timeTxt:GTextFiled;
        protected var _timeDes:GTextFiled;
        protected var _getRwBtn:GLoadingButton;
        protected var _repeatTip:GImageBitmap;
        protected var _item:BaseItem;
        protected var _canGetNum:GTextFiled;
        private var _oldNum:int = -1;
        private static var _instance:OpenServerSevDayRC200;

        public function OpenServerSevDayRC200(param1:ILayer = null)
        {
            super(param1);
            setSize(341, 415);
            title = "" + Language.getString(71813);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap(ImagesConst.OpenServerSevDayRC200Bg, 7, 35, this);
            this._namtTxt = UIFactory.gTextField("", 126, 267, 100, 20, this, GlobalStyle.textFormatZi.center());
            this._des = UIFactory.gTextField("", 12, 283, 330, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).center());
            this._comsumNum = UIFactory.gTextField("25689", 86, 328, 100, 20, this, GlobalStyle.textFormatHuang2);
            this._timeTxt = UIFactory.gTextField("50/50", 232, 328, 100, 20, this, GlobalStyle.textFormatHuang2);
            this._timeDes = UIFactory.gTextField("" + Language.getString(71814), 268, 327, 100, 20, this, GlobalStyle.textFormatLv);
            this._getRwBtn = UIFactory.gLoadingButton(ImagesConst.TakeRewardBtn_upSkin, 113, 359, 130, 44, this);
            this._getRwBtn.label = "";
            this._repeatTip = UIFactory.gImageBitmap(ImagesConst.RebateDayRechargeRepeat2, 121, 304, this);
            this._item = UIFactory.getUICompoment(BaseItem);
            this._item.setItemStyle(ItemStyleConst.Big, ImagesConst.ShopItemBg, 6, 6);
            UIFactory.setObjAttri(this._item, 140, 186, -1, -1, this);
            this._canGetNum = UIFactory.gTextField("", 217, 237, 100, 20, this, GlobalStyle.textFormatLv);
            this.updateInfo();
            this._getRwBtn.configEventListener(MouseEvent.CLICK, this.getHd);
            this._oldNum = Cache.instance.openServerSevenDay.consumRewardInfo.getTimes;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._oldNum = -1;
            this._bg = null;
            this._namtTxt = null;
            this._des = null;
            this._comsumNum = null;
            this._timeTxt = null;
            this._timeDes = null;
            this._getRwBtn = null;
            this._repeatTip = null;
            this._item = null;
            this._canGetNum = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateInfo() : void
        {
            var _loc_5:ItemData = null;
            var _loc_1:* = RebateUtil.getType();
            var _loc_2:* = RebateUtil.getTargetType();
            var _loc_3:* = RebateUtil.getTodayConsum();
            if (_loc_3 != 0)
            {
                _loc_5 = new ItemData(_loc_3);
                this._item.itemData = _loc_5;
                this._namtTxt.htmlText = HTMLUtil.addColor(_loc_5.itemInfo.name, "#d618dd");
                this._des.text = "" + this._item.itemData.itemInfo.descStr;
            }
            else
            {
                this._getRwBtn.enabled = false;
            }
            if (this._oldNum != -1 && this._oldNum != Cache.instance.openServerSevenDay.consumRewardInfo.getTimes)
            {
                this._oldNum = Cache.instance.openServerSevenDay.consumRewardInfo.getTimes;
                this.flyIcon();
                MsgManager.showRollTipsMsg("" + Language.getString(71815));
            }
            this._comsumNum.text = "" + Cache.instance.openServerSevenDay.consumRewardInfo.consumNum;
            var _loc_4:* = Cache.instance.openServerSevenDay.consumRewardInfo.getTimes;
            this._timeTxt.text = "" + _loc_4 + "/" + Cache.instance.openServerSevenDay.comsumTotalNum;
            if (RebateUtil.hasConsumRw())
            {
                this._getRwBtn.enabled = true;
                this._getRwBtn.filters = null;
            }
            else
            {
                this._getRwBtn.enabled = false;
                this._getRwBtn.filters = [FilterConst.colorFilter2];
            }
            this.updateCanGetTime();
            return;
        }// end function

        private function updateCanGetTime() : void
        {
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_1:* = Cache.instance.openServerSevenDay.consumRewardInfo;
            var _loc_2:* = _loc_1.getTimes;
            var _loc_3:* = _loc_1.consumNum;
            var _loc_4:* = Cache.instance.openServerSevenDay.comsumTotalNum;
            var _loc_5:* = Cache.instance.openServerSevenDay.comsumOneMoney;
            if (_loc_2 < _loc_4)
            {
                _loc_6 = _loc_4 - _loc_2;
                _loc_7 = _loc_3 / _loc_5;
                _loc_7 = _loc_7 - _loc_2;
                if (_loc_7 > _loc_6)
                {
                    _loc_7 = _loc_6;
                }
                if (_loc_7 == 0)
                {
                    this._canGetNum.visible = false;
                }
                else
                {
                    this._canGetNum.visible = true;
                    this._canGetNum.text = Language.getStringByParam(71816, _loc_7);
                }
            }
            else
            {
                this._canGetNum.visible = false;
            }
            return;
        }// end function

        private function flyIcon() : void
        {
            var _loc_1:Point = null;
            if (this._item && this._item.bitmapdata)
            {
                _loc_1 = this._item.localToGlobal(GameConst.yellowPoint);
                FlyToNavbarTool.flyBitmapOriginalToPack(this._item.bitmapdata, _loc_1);
            }
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            this.x = (Global.stage.stageWidth - this.width) / 2;
            this.y = (Global.stage.stageHeight - this.height) / 2;
            return;
        }// end function

        private function getHd(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RebateOpenSerSenRC200GetRw));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            if (OpenServerSevenDayUtil.isNotOpenSpeActive())
            {
                return;
            }
            super.show(param1, param2);
            return;
        }// end function

        public static function get instance() : OpenServerSevDayRC200
        {
            if (!_instance)
            {
                _instance = new OpenServerSevDayRC200;
            }
            return _instance;
        }// end function

        public static function isView() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
